const router = require('express').Router()


var code = parseInt(Math.random() * 1000000)
// 登录接口
router.get('/sends', (req, res) => {
    let mobile = req.query.mo
    //node request模块安装命令：npm install request
    var request = require('request');
    var querystring = require('querystring');

    var queryData = querystring.stringify({
        "mobile": mobile, // 接受短信的用户手机号码
        "tpl_id": "199962", // 您申请的短信模板ID，根据实际情况修改
        "tpl_value": `#code#=${code}`, // 您设置的模板变量，根据实际情况修改
        "key": "8f362745bef15a0d2bb94690dad953ff", // 应用APPKEY(应用详细页查询)
    });

    var queryUrl = 'http://v.juhe.cn/sms/send?' + queryData;

    request(queryUrl, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            // console.log(body) // 打印接口返回内容

            var jsonObj = JSON.parse(body); // 解析接口返回的JSON内容
            // console.log(jsonObj)
        } else {
            console.log('请求异常');
        }
    })
})

router.get('/verilogin',(req,res)=>{
    let verify =Number(req.query.verify)
    if(verify!==code){
        res.json({
            'ok':0,
            "error":"验证码错误!"
        })
        return false
    }else{
res.json({
    "ok":1,
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiaWF0IjoxNTc0MjExNTMzLCJleHAiOjE1ODk3NjM1MzN9.n5b86adpWbKFmP1-tq_-QWaAEJ5t0r5V0N2jtOdY42Y"
})
    }
})







module.exports = router








